package org.ting.e_commerce.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.ting.e_commerce.model.UserAddress;

import java.util.List;

@Mapper
public interface UserAddressMapper {
    @Insert("insert into user_address(user_id, address_detail, consignee, contact_phone) values(#{userId}, #{addressDetail}, #{consignee}, #{contactPhone})")
    boolean addUserAddress(UserAddress address);
    @Select("select * from user_address where user_id = #{userId} and is_default = false")
    List<UserAddress> getNoDefaultAddress(int userId);

    @Select("select * from user_address where user_id = #{userId} and is_default = true")
    UserAddress getDefaultAddress(int userId);

    @Select("select * from user_address where address_id = #{addressId}")
    UserAddress getAddressById(int addressId);
    @Delete("delete from user_address where address_id = #{addressId}")
    boolean deleteById(int addressId);

    boolean updateById(UserAddress address);
}
